package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsCoupon;
import com.qf.pojo.DtsCouponUser;
import com.qf.service.DtsCouponUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class DtsCouponUserServiceImpl implements DtsCouponUserService {

    @Autowired
    DtsCouponUserMapper couponUserMapper;

    @Override
    public IPage<DtsCouponUser> queryPage(Integer page, Integer limit, String sort, String order, Integer couponId, Integer userId, Integer status) {
        IPage<DtsCouponUser> iPage = new Page<>(page,limit);
        QueryWrapper<DtsCouponUser> qw = new QueryWrapper<>();
        if(userId != null){
            qw.eq("`user_id`",userId);
        }
        if(couponId != null){
            qw.eq("`coupon_id`",couponId);
        }
        if (status != null){
            qw.eq("status",status);
        }
        qw.eq("deleted",false);
        if(!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)){
            if(order.equalsIgnoreCase("desc")){
                qw.orderByDesc(sort);
            }else {
                qw.orderByAsc(sort);
            }
        }
        couponUserMapper.selectPage(iPage,qw);
        return iPage;
    }
}
